package com.zengdada.authority.utils.where.result;

import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zsa
 * @date 2020/9/10 14:18
 * @description TODO
 */
public class AnalysisResult {
    private String rel = "AND";
    private final List<String> extraFilters = new ArrayList<>(1);
    private final List<Object> paramValues = new ArrayList<>(1);
    private final List<String> anyWhereExtraFilters = new ArrayList<>(1);
    private final List<Object> anyWhereParamValues = new ArrayList<>(1);

    public boolean isNull() {
        return extraFilters.isEmpty() && paramValues.isEmpty() && anyWhereExtraFilters.isEmpty() && anyWhereParamValues.isEmpty();
    }

    public String getRel() {
        return rel;
    }

    public void setRel(String rel) {
        this.rel = rel;
    }

    public List<String> addExtraFilter(String extraFilter) {
        if (StringUtils.isBlank(extraFilter)) {
            return this.extraFilters;
        }
        extraFilters.add(extraFilter);
        return extraFilters;
    }

    public List<Object> addParamValue(Object paramValue) {
        paramValues.add(paramValue);
        return paramValues;
    }

    public List<Object> addAllParamValues(List<Object> paramValues) {
        if (paramValues == null) {
            return this.paramValues;
        }
        this.paramValues.addAll(paramValues);
        return this.paramValues;
    }

    public List<String> addAnyWhereExtraFilter(String extraFilter) {
        if (StringUtils.isBlank(extraFilter)) {
            return this.anyWhereExtraFilters;
        }
        anyWhereExtraFilters.add(extraFilter);
        return anyWhereExtraFilters;
    }

    public List<Object> addAnyWhereParamValues(Object paramValue) {
        anyWhereParamValues.add(paramValue);
        return anyWhereParamValues;
    }

    public List<Object> addAllAnyWhereParamValues(List<Object> paramValues) {
        if (paramValues == null) {
            return this.anyWhereParamValues;
        }
        this.anyWhereParamValues.addAll(paramValues);
        return anyWhereParamValues;
    }

    public List<String> getExtraFilters() {
        return extraFilters;
    }

    public List<Object> getParamValues() {
        return paramValues;
    }

    public List<String> getAnyWhereExtraFilters() {
        return anyWhereExtraFilters;
    }

    public List<Object> getAnyWhereParamValues() {
        return anyWhereParamValues;
    }

    public void addAnalysisResultMerge(AnalysisResultMerge analysisResultMerge) {
        addAllParamValues(analysisResultMerge.getParamValues());
        addAllAnyWhereParamValues(analysisResultMerge.getAnyWhereParamValues());
        addExtraFilter(analysisResultMerge.getExtraFilter());
        addAnyWhereExtraFilter(analysisResultMerge.getAnyWhereExtraFilter());
    }
}
